<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="java.net.URLDecoder"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="des" scope="request" class="accessibleworldsdes.AccessibleWorldsDESJavaBeans"/>
<%try {

String accessCode = request.getParameter("accessCode");

if(!(accessCode==null || "".equals(accessCode))) {
	
    accessCode = des.decryptString(des.getServiceSecretKey(), accessCode);
    accessCode = URLDecoder.decode(accessCode, "UTF-8");
    
    if(des.getAndroidAccessCode().equals(accessCode) || des.getComputerAccessCode().equals(accessCode)) {
    	
    	String videoID = request.getParameter("videoID");
    	
    	if(!(videoID == null || "".equalsIgnoreCase(videoID))) {
    		
    		videoID = des.decryptString(des.getServiceSecretKey(), videoID);
    		videoID = URLDecoder.decode(videoID, "UTF-8");
    		
    		File videoFile = new File(getServletContext().getInitParameter("mediaLocation")+videoID+".3gp");
    		if(videoFile.exists()) {
    			response.setContentType("application/octet-stream");
    		    String header = "Attachment; Filename=\""+videoID+".3gp"+"\"";
    		    response.setHeader("Content-Disposition", header);
    		    response.setContentLength((int)videoFile.length());
    		    
    		    ServletOutputStream output = response.getOutputStream();
    		    
    		    InputStream inputStream = new BufferedInputStream(new FileInputStream(videoFile));
    		    
    		    int read;
    		    while ((read=inputStream.read())!=-1) {
    		        output.print((char)read);
    		    }
    		    inputStream.close();
    		    output.flush();
    		    output.close();
    		}
    	}
    }
}
} catch (Exception ex) {}%>